package com.jsu.hotelmanagement.controller;

import com.alibaba.fastjson.JSON;
import com.jsu.hotelmanagement.pojo.dto.CheckInUserDTO;
import com.jsu.hotelmanagement.pojo.dto.RoomStatisticsStatusDTO;
import com.jsu.hotelmanagement.pojo.po.OrdersInfoVO;
import com.jsu.hotelmanagement.pojo.vo.CommonResult;
import com.jsu.hotelmanagement.pojo.vo.RoomStatusVO;
import com.jsu.hotelmanagement.service.RoomService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mo
 * @createTime 2022/12/7 11:43
 * @description
 */
@RestController
@RequestMapping("/room")
public class RoomController {
    @Autowired
    RoomService roomService;

    @GetMapping("/getRoomStatistics")
    public CommonResult getRoomStatistics() {
        return roomService.getRoomStatistics();
    }

    @GetMapping("/queryRoomDetailInfoList")
    public CommonResult queryRoomDetailInfoList() {
        return roomService.queryRoomDetailInfoList();
    }

    @PostMapping("/guestCheckOut")
    public CommonResult checkOut(@RequestBody String data) {
        int roomId = Integer.parseInt(JSON.parseObject(data).getString("roomId"));
        System.out.println(roomId);
        return roomService.guestCheckOut(roomId);
    }

    @PostMapping("/updateRoomStatus")
    public CommonResult updateRoomStatus(@RequestBody RoomStatusVO roomStatusVO) {
        return roomService.updateRoomStatus(roomStatusVO);
    }

    @PostMapping("/finishedCleanStatus")
    public CommonResult finishedCleanStatus(@RequestBody String data) {
        int roomId = Integer.parseInt(JSON.parseObject(data).getString("roomId"));
        return roomService.finishedCleanStatus(roomId);
    }

    @PostMapping("/cancelOrder")
    public CommonResult cancelOrder(@RequestBody String data) {
        int roomId = Integer.parseInt(JSON.parseObject(data).getString("roomId"));
        return roomService.cancelOrder(roomId);
    }

    @GetMapping("/queryOrderUserInfo/{roomId}")
    public CommonResult queryOrderUserInfo(@PathVariable("roomId") Integer roomId) {
        return roomService.queryOrderUserInfo(roomId);
    }

    @GetMapping("/queryRoomGuestInfo/{roomId}")
    public CommonResult queryRoomGuestInfo(@PathVariable("roomId") Integer roomId) {
        return roomService.queryRoomGuestInfo(roomId);
    }

    @PostMapping("/checkInUser")
    public CommonResult checkInUser(@RequestBody CheckInUserDTO checkInUserDTO) {
        return roomService.checkInUser(checkInUserDTO);
    }

    @PostMapping("/insertOrdersInfo")
    public CommonResult<Integer> insertOrdersInfo(@RequestBody OrdersInfoVO ordersInfoVO){
        return roomService.insertOrdersInfo(ordersInfoVO);
    }

    @GetMapping("/modifyEndtime")
    @ApiOperation("重置计时器")
    public CommonResult<Integer> modifyEndtime(@RequestParam Integer roomId) {
        Integer i = roomService.modifyEndtime(roomId);
        if (i > 0) {
            return new CommonResult<>(200, "修改时间成功！");
        } else {
            return new CommonResult<>(444, "修改时间失败!");
        }
    }
}
